-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Refactor check of http Response.ContentLength #1615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Codecov Report
@@ Coverage Diff @@
## master #1615 +/- ##
=======================================
Coverage 68.04% 68.04%
=======================================
Files 97 97
Lines 8830 8830
=======================================
Hits 6008 6008
Misses 1908 1908
Partials 914 914
Continue to review full report at Codecov.
|
@@ -569,7 +569,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res | |||
// re-used. No need to check for errors: if it fails, the Transport | |||
// won't reuse it anyway. | |||
const maxBodySlurpSize = 2 << 10 | |||
if resp.ContentLength == -1 || resp.ContentLength <= maxBodySlurpSize { | |||
if resp.ContentLength <= maxBodySlurpSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this instead?
if resp.ContentLength <= maxBodySlurpSize { | |
if resp.ContentLength != 0 && resp.ContentLength <= maxBodySlurpSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And while you are making tweaks, how about wrapping lines 572-576 with a check like:
if resp != nil {
...
}
@gmlewis @linux019
Please check it here. https://golang.org/pkg/net/http/ |
Closing this PR in favor of #1645. |
The check
resp.ContentLength <= maxBodySlurpSize
supersedesresp.ContentLength == -1
as ContentLength is signed int64https://play.golang.org/p/Io9U59wxxkK